using System;
using ScienceNET.Optimization;

namespace OptimizationDemo1
{
        class Model : IOpimizable
        {
            public int ParametersNumber { get { return 2; } }
            public ComputeEnum AllowedComputations { get { return ComputeEnum.FunctionValue | ComputeEnum.Gradient; } }

            public void Compute(ComputeEnum c, IOptimizer optimizer)
            {
                optimizer.FunctionValue = Math.Pow(optimizer.Parameters[0] - 3, 2) + Math.Pow(optimizer.Parameters[1] + 1, 2);
                optimizer.Gradient[0] = 2 * (optimizer.Parameters[0] - 3);
                optimizer.Gradient[1] = 2 * (optimizer.Parameters[1] + 1);
            }

        }

        class Program
        {
            static void Main(string[] args)
            {
                Model mod = new Model();

                OptimizerGM optimizerGM = new OptimizerGM(mod);
                optimizerGM.Optimize();
                Console.WriteLine("Result: X1={0} X2={1}", optimizerGM.Parameters[0], optimizerGM.Parameters[1]);
                
                OptimizerRP optimizerRP = new OptimizerRP(mod);
                optimizerRP.Optimize();
                Console.WriteLine("Result: X1={0} X2={1}", optimizerRP.Parameters[0], optimizerRP.Parameters[1]);


                Console.ReadLine();
            }
        }
    }

